package ch.unisi.inf.pfii.teamwhite.risk.graphic.mapEditor;

/**
 * @author Andrea Michelotti: micheloa@lu.unisi.ch
 */

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

public final class FileCreator {

	private File xyFile;
	private File neighFile;

	public final void createCoordinatesFile (final String mapName) {
		xyFile = new File(mapName + ".wsh.xy");
	}
	
	public final void writeCoordinates(final ArrayList<String[]> galaxy, final int x, final int y) {
		try {
			int counter = 0;
			BufferedWriter writer = new BufferedWriter(new FileWriter(xyFile, true));
			for (String[] line : galaxy) {
			    writer.write(line[0] + " " + line[1] + " " + line[2]);
			    writer.newLine();
			    counter++;
			    if (counter == 42) {
			    	writer.close();
			    }
			}
		} catch (IOException e) {
		}
	}

	public final void createNeighboursFile (final String mapName) {
		xyFile = new File(mapName + ".wsh.neigh");
	}
	
	public final void writeNeighbours(final ArrayList<String[]> neighbours) {
		try {
			int counter = 0;
			BufferedWriter writer = new BufferedWriter(new FileWriter(neighFile, true));
			for (String[] line : neighbours) {
				String toPrint = "";
				for (int i = 0; i < line.length; i++) {
					toPrint = toPrint + line[i];
				}
			    writer.write(toPrint);
			    writer.newLine();
			    counter++;
			    if (counter == 42) {
			    	writer.close();
			    }
			}
		} catch (IOException e) {
		}
	}
}
